package com.longge;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class CountWords {

    public int countWords(String[] words1, String[] words2) {

        HashMap<String, Integer> map1 = new HashMap<>();
        HashMap<String, Integer> map2 = new HashMap<>();
        for (String s : words1) {
            map1.put(s,map1.getOrDefault(s,0)+1);
        }
        for (String s : words2) {
            map2.put(s,map2.getOrDefault(s,0)+1);
        }
        int ans = 0;
        for (Map.Entry<String, Integer> entry : map1.entrySet()) {
            String k1 = entry.getKey();
            Integer v1 = entry.getValue();
            if (v1 == 1) {
                Integer v2 = map2.get(k1);
                if (Objects.nonNull(v2)&&v2==1){
                    ans++;
                }
            }
        }
        return ans;
    }
}
